package com.wn.deadLetterchange;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

@Component
public class DeadLetterConsumer {

    @Autowired
    JavaMailSender javaMailSender;

    @RabbitListener(queues = "letterQueueA")
    public void receiveLetterA(Map<String , String> emailLetter, Message message, Channel channel) throws IOException {
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        mailMessage.setFrom("3300461359@qq.com");
        mailMessage.setTo(emailLetter.get("email"));
        mailMessage.setSubject(emailLetter.get("subject"));
        mailMessage.setText(emailLetter.get("text"));
        javaMailSender.send(mailMessage);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }


}
